package com.xuan.juc.forkjoin;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

public class test {
    public static void main(String[] args) {
    test2();
    }

    public static void test1(){
        long start = System.currentTimeMillis();
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        ForkJoinTest task = new ForkJoinTest(1L, 10000L);
        ForkJoinTask<Long> submit = forkJoinPool.submit(task);
        try {
            submit.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();

        forkJoinPool.shutdown();
        System.out.println(end-start);

    }

    public static void test2(){
        long start = System.currentTimeMillis();
        LongStream.range(1L, 10000L).parallel().reduce(0,Long::sum);
        long end = System.currentTimeMillis();

        System.out.println(end-start);
    }

}